package org.jeecg.modules.service.impl;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.modules.client.ClientUrlConstant;
import org.jeecg.modules.client.HttpClient;
import org.jeecg.modules.dto.station.*;
import org.jeecg.modules.service.StationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class StationServiceImpl implements StationService {

    private static final Logger log_server = LoggerFactory.getLogger("netty-info");

    @Value("${application.openUrl}")
    private String httpUrl;

    /**
     * 下发车桩状态修改
     */
    @Override
    public Result<?> pileRegister(StationRegisterRsp stationRegisterRsp) {
        log_server.info("下发车桩状态修改请求 ========== :{}", JSON.toJSONString(stationRegisterRsp));
        Result<?> resResult = HttpClient.doClassPost(httpUrl + ClientUrlConstant.pile_register, stationRegisterRsp);
        if (resResult.getCode() != CommonConstant.SC_OK_200){
            return Result.error("请求失败，网点已断线！");
        }
        return resResult;
    }

    /**
     * 下发所有网点滚屏公告
     */
    @Override
    public Result<?> notice() {
        log_server.info("所有网点下发滚屏公告请求 ========== :{}");
        NoticeReq noticeReq = new NoticeReq();
        Result<?> resResult = HttpClient.doClassPost(httpUrl + ClientUrlConstant.notice, noticeReq);
        if (resResult.getCode() != CommonConstant.SC_OK_200){
            return Result.error("请求失败，网点已断线！");
        }
        return resResult;
    }

    /**
     * 全网点管理员卡号列表更新
     */
    @Override
    public Result<?> manageCardListByStation() {
        log_server.info("全网点管理员卡号列表更新 ========== :{}");
        ManageCardListReq manageCardListReq = new ManageCardListReq();
        Result<?> resResult = HttpClient.doClassPost(httpUrl + ClientUrlConstant.manage_card_list_by_station, manageCardListReq);
        if (resResult.getCode() != CommonConstant.SC_OK_200){
            return Result.error("请求失败，网点已断线！");
        }
        return resResult;
    }

    /**
     * 管理员卡号列表更新
     * @param manageCardListReq
     */
    @Override
    public Result<?> manageCardList(ManageCardListReq manageCardListReq) {
        log_server.info("管理员卡号列表下发请求 ==========  :{}", JSON.toJSONString(manageCardListReq));
        Result<?> resResult = HttpClient.doClassPost(httpUrl + ClientUrlConstant.manage_card_list, manageCardListReq);
        if (resResult.getCode() != CommonConstant.SC_OK_200){
            return Result.error("请求失败，网点已断线！");
        }
        return resResult;
    }
}
